package org.evolAI.organism.dao;

import java.util.UUID;

import org.evolAI.organism.domain.Organism;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class HibernateOrganismDAO implements OrganismDAO {

	private SessionFactory sessionFactory;
	
	@Autowired
	public HibernateOrganismDAO(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	private Session currentSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public void addOrganism(Organism organism) {
		currentSession().save(organism);
	}

	@Override
	public void saveOrganism(Organism organism) {
		currentSession().update(organism);
	}

	@Override
	public Organism findOrganism(UUID id) {
		return (Organism) currentSession().get(Organism.class, id);
	}
}
